package my.mall.db.config

import com.baomidou.mybatisplus.annotation.DbType
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.transaction.annotation.EnableTransactionManagement

@Configuration
@EnableTransactionManagement(proxyTargetClass = true)
open class MybatisPlusConfig {

    @Bean
    open fun mybatisPlusInterceptor(): MybatisPlusInterceptor {
        val interceptor = MybatisPlusInterceptor()
        val paginationInnerInterceptor = PaginationInnerInterceptor()
        paginationInnerInterceptor.isOptimizeJoin = true
        paginationInnerInterceptor.dbType = DbType.MYSQL
        paginationInnerInterceptor.isOverflow = true
        interceptor.addInnerInterceptor(paginationInnerInterceptor)
        val optimisticLockerInnerInterceptor = OptimisticLockerInnerInterceptor()
        interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor);
        return interceptor;
    }
}